import React from 'react'
import { observable, action, toJS, computed } from 'mobx';
import { Tools, Popover } from 'weaver-mobile'
import { SearchAdvanced, ListAdvanced, RouteLayout, Browser, BrowserHrm, Upload,ListViewPage } from 'weaver-mobile-page';
import * as GoalBaseAPI from '../../api/goal/goalBase';
const getLabel = Tools.getLabel;

export default class GoalOperateLogStore {

    
    @observable
    datas = []

    @action
    changeDatas = (datas) => {
        this.datas = datas
    }

    @observable
    lastcount = 0

    @action
    changeLastcount = (lastcount) => {
        this.lastcount = lastcount
    }

    @observable
    lastid = ""

    @action
    changeLastid = (lastid) => {
        this.lastid = lastid
    }

    @observable
    goalId = ""

    @action
    changeGoalId = (goalId) => {
        this.goalId = goalId
    }

    @computed
    get logStore() {
        return new ListViewPage.Store({ route: '/goalHome/goalDetail/' + this.goalId })
    }

        //获取目标操作日志
    @action
    getGoalLog = (flag = false) => {
        GoalBaseAPI.getGoalLog({
            goalId:this.goalId,
            pagesize: 20,
            lastcount: this.lastcount,
            lastid: this.lastid,
        }).then(res => {
            if (res.status) {
                let tempArray = toJS(this.datas)
                tempArray.push(...res.list)
                this.datas = tempArray

                const newState = {
                    isTable: false,
                    loading: false,
                    haveCheck: false,
                    template: { default: [] },
                    hasMore: res.lastlogcount > 0 ? true : false,
                    data:flag ?  res.list : res.list && this.logStore.data.concat(res.list)
                }
                this.logStore.setState(newState)
                this.logStore.updateDataSource()
                this.lastcount = res.lastlogcount;
                this.lastid = res.lastlogid;
            }
        })

    }


}